package com.zhangliuliu.service.impl;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhangliuliu.bean.AreaBean;
import com.zhangliuliu.bean.EventBean;
import com.zhangliuliu.dao.ContactDao;
import com.zhangliuliu.dao.EventDao;
import com.zhangliuliu.service.EventService;
import com.zhangliuliu.service.ExpertService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.time.LocalDate;

@Service
@Transactional
public class EventServiceImpl extends ServiceImpl<EventDao, EventBean>implements EventService {
    @Resource
    private ContactDao contactDao;
    @Override
    public void addEvent(EventBean eventBean) {
        this.baseMapper.add(eventBean);
    }

    @Override
    public void addRelation(int eventId, Integer[] consultId) {
        this.contactDao.addRelation(eventId,consultId);
    }

    @Override
    public EventBean getAll(int id) {
       return this.baseMapper.select(id);

    }

    @Override
    public void updateById(int id, String stage, String plan) {
        EventBean eventBean = new EventBean();
        eventBean.setEventId(id);
        eventBean.setStage(stage);
        eventBean.setPlan(plan);
        updateById(eventBean);
    }

    @Override
    public IPage<EventBean> cutByItem(int pageNo, int pageSize, String name, String stage,
                                      AreaBean location, LocalDate start, LocalDate end) {


         Page<EventBean> Page = new Page<>(pageNo,pageSize);
         QueryWrapper wrapper = new QueryWrapper();
        if (name!=null&& !name.equals("")){
             wrapper.eq("event_name",name);
         }
        if (stage!=null&& !stage.equals("")){
            wrapper.eq("event_stage",stage);
        }
        if (location!=null&& !location.equals("")){
            wrapper.eq("fk_areaId",location.getAreaId());
        }
        if (start!=null){
            wrapper.lt("event_time",start);
        }
        if (end!=null){
            wrapper.gt("event_time",end);
        }

        return this.page(Page,wrapper);
    }
}
